
const { BrowserWindow, ipcMain,globalShortcut} = require("electron")

const {enable} = require('@/util/enable');
const path = require('path')
const file = require('@/util/file')

let win = null

export function createSetShopWin(success) {
  win = new BrowserWindow({
    width: 400,
    height: 400,
    title: "门店设置",
    resizable: false,
    maximizable: false,
    frame: false,
    transparent: true,
    modal: true,
    // parent:win,
    show: true,//是否显示界面 先设置否
    icon: path.join(__dirname, 'logo.ico'),
    webPreferences: {
      partition: String(+new Date()),
      plugins: true, //是否支持插件
      nodeIntegration: true,
      contextIsolation: false,
      webViewTag: true,
      webSecurity: false,
      enableRemoteModule: true
    }
  });
  win.setMenu(null);

  globalShortcut.register('CommandOrControl+Alt+s', function () {
    win.webContents.openDevTools({mode: 'detach'})
  })
  if (process.env.ENV == 'development') {
    win.loadURL(`${process.env.VUE_APP_WEB_DOMAIN}/setShop`, { extraHeaders: "pragma: no-cache\n" });
  } else {
    win.loadURL(`file://${path.join(__dirname, 'index.html')}#/setShop`);
  }
  enable(win);

  ipcMain.on("window-set-shop", (event, obj) => {
    file.configWrite(obj).then(() => {
      win.hide()
      win = null
      success(obj)
    })
  });
  win.once('ready-to-show', () => {
    win.show();
  });
  win.on("closed", () => {
    win = null;
  })
}
